function find(dataList) {
    var query = {};

    query.where = function where(condition) {
        var conditionKeys = Object.keys(condition);
        dataList = dataList.filter((item) => {
            return conditionKeys.every(key => condition[key].test(item[key]));
        })
        return query;
    }

    query.orderBy = function orderBy(key, direction) {
        dataList.sort((a, b) => {
            return direction === 'desc' ? b[key] - a[key] : a[key] - b[key];
        })
        return dataList;
    }
    return query;
}

// TEST
var data = [
    {id: 1, title: 'title1'},
    {id: 2, title: 'other'},
    {id: 3, title: null},
    {id: 4, title: 'title2'}
];

//查找data中，符合条件的数据，并进行排序
var result = find(data).where({
    "title": /\d$/
}).orderBy('id', 'desc');

console.log(result);